import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';

export interface LoginData {
  username: string;
  password: string;
}

export interface LoginRes {
  token: string;
  name: string;
  access: string;
  email: string;
  forcePassWord: number;
}
export interface CaptchaRes {
  image: string;
  captchaCode: string;
}

export function login(data: LoginData) {
  return axios.post<LoginRes>('/admin/api/auth/login', data);
}

export function captcha() {
  return axios.post<CaptchaRes>('/admin/api/auth/captcha');
}

export function logout() {
  return axios.post<LoginRes>('/admin/api/auth/logout');
}

export function changePassword(data: any) {
  return axios.post('/admin/api/profile/changePassWord', data);
}

export function getUserInfo() {
  const timestamp = new Date().getTime();
  return axios.get<UserState>(`/admin/api/profile/info`);
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/admin/api/user/menu');
}
